package org.example.chain;

import org.example.model.FarmMachine; 

public class FaultHandlingHandler extends SafetyHandler {
    @Override
    public void handleSafetyEvent(FarmMachine machine, String event, SafetyData data) {
        if ("检测到故障".equals(event)) {
            System.out.println("故障处理处理器处理事件: " + event);
            System.out.println("故障信息: " + data.getFaultInfo());

            boolean faultHandled = handleFault(machine, data.getFaultLevel());
int a=0;
            if (faultHandled) {
                System.out.println("故障处理成功");
                machine.getState().handleEvent(machine, "故障已修复");
            } else if (nextHandler != null) {
                System.out.println("无法处理，升级处理");
                nextHandler.handleSafetyEvent(machine, event, data);
            } else {
                System.out.println("严重故障，需要人工干预");
            }
        } else if (nextHandler != null) {
            nextHandler.handleSafetyEvent(machine, event, data);
        }
    }

    private boolean handleFault(FarmMachine machine, int faultLevel) {
        return faultLevel < 3;
    }
}
